package carltechnology.com.mahjonggame.utils.dao.impl;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

/**
 * Created by WZTCM on 2016/6/1.
 */
public class MyDataBaseHelper extends SQLiteOpenHelper {
    enum DATABASE_INFO {
        DB_NAME("mahjong.db"),
        CREATE_MAHJONGTABLE("create table game ("
                + "id INTEGER PRIMARY KEY   AUTOINCREMENT,"
                + "name text not null,"
                + "date text not null)"),
        MAHJONGGAME_DATABASE_NAME("game"),
//        MAHJONGGAME_TABLE1("name"),
//        MAHJONGGAME_TABLE2("date"),
      //  INSERT_HKL("insert into game (name,date) values('hkl_ct_wx_sj','1992-10-12')"),
        INSERT("insert into gamedetail(id,income1,income2,income3,income4,cost,perunit,date)" +
        " values(1,100,200,300,100,20,2,'1992-10-12')"),
        CREATE_MAHJONGGAME_DETAIL("create table gamedetail ("
                + "id INTEGER ," +
                "perid INTEGER PRIMARY KEY   AUTOINCREMENT," +
                "income1 integer not null," +
                "income2 integer not null," +
                "income3 integer not null," +
                "income4 integer not null," +
                "cost integer not null," +
                "perunit integer not null," +
                "date text not null)");
        private String string;

        DATABASE_INFO(String string) {
            this.string = string;
        }

        @Override
        public String toString() {
            return string;
        }
    }

    //    private static final String CREATE_MAHJONGTABLE =
    //            "create table Game ("+
    //                    "id integer autoincrement," +
    //                    "name text primary key," +
    //                    "date text)";
    //    private static final String INSERT_HKL ="" +
    //            "insert into Game (name,date) values(hkl_ct_wx_sj,1992-10-12)";
    private Context mContext;

    public MyDataBaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(DATABASE_INFO.CREATE_MAHJONGTABLE.toString());
       // db.execSQL(DATABASE_INFO.INSERT_HKL.toString());
        db.execSQL(DATABASE_INFO.CREATE_MAHJONGGAME_DETAIL.toString());
        db.execSQL(DATABASE_INFO.INSERT.toString());
        Toast.makeText(mContext, "SQL SUCCESSED", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
}
